package com.qixin.web.util;

import com.qixin.api.bean.ComPeople;
import com.qixin.api.bean.ComPtUser;

import javax.servlet.http.HttpSession;

/**
 * Created by Zhang on 2018/11/1.
 */
public class SessionUtil {
    public static  Long getUserId(HttpSession session){
        //获取session  userId
        ComPtUser comPtUser =new ComPtUser();
        ComPeople comPeople=new ComPeople();
        Long userId=0L;
        if(session.getAttribute("people_user")!=null){
            comPeople=(ComPeople)session.getAttribute("people_user");
            userId=comPeople.getId();
        }else {
            if(session.getAttribute("pt_user")!=null){
                comPtUser=(ComPtUser)session.getAttribute("pt_user");
                userId=comPtUser.getId();
            }
        }
        return userId;
    }

    /**
     * 获取登陆用户 是个人 还是企业
     * @param session
     * @return  1 企业  2 个人
     */
    public static  int getUserFlag(HttpSession session){
        ComPtUser comPtUser =new ComPtUser();
        ComPeople comPeople=new ComPeople();
        int flag=0;
        if(session.getAttribute("people_user")!=null){
            flag=2;
        }else {
            if(session.getAttribute("pt_user")!=null){
                flag=1;
            }
        }
        return flag;
    }

    /**
     * 获取登陆用户的手机号
     * @param session
     * @return
     */
    public static  String getUserPhone(HttpSession session){
        ComPtUser comPtUser =new ComPtUser();
        ComPeople comPeople=new ComPeople();
        String  phone="";
        if(session.getAttribute("people_user")!=null){
            comPeople=(ComPeople)session.getAttribute("people_user");
            phone=comPeople.getPhone()+"";
        }else {
            if(session.getAttribute("pt_user")!=null){
                comPtUser=(ComPtUser)session.getAttribute("pt_user");
                phone=comPtUser.getCallPhone();
            }
        }
        return phone;
    }
}
